package com.singbon.server.security;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;
import org.springframework.stereotype.Service;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
/**
 */
@Slf4j
@Service
public class SsoInMemoryAuthorizationCodeServicesImpl extends InMemoryAuthorizationCodeServices {
  @Autowired
  private HttpServletRequest request;
  @Override
  protected void store(String code, OAuth2Authentication authentication) {
    log.info(code);
    log.info(authentication.getName());
    String ssoSessionId = request.getSession().getId();
    log.info(ssoSessionId);
    ServletContext context = request.getServletContext();
    context.setAttribute(code, ssoSessionId);
    super.store(code, authentication);
  }
}
